<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> 
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" > 

<html>
<head>
<base href="<%=basePath%>">
<title>药品详情</title>
<link rel="stylesheet" href="./js/bootstrap-3.3.5-dist/css/bootstrap.css" type="text/css"/>
<link rel="stylesheet" href="./js/metisMenu/metisMenu.min.css">
<link rel="stylesheet" href="./css/sb-admin/sb-admin-2.css">
<link rel="stylesheet" href="./css/base.css">
<link rel="stylesheet" href="./css/illness.css">
<link rel="stylesheet" href="./js/font-awesome/css/font-awesome.min.css">
<link rel="stylesheet" href="./js/bootstrap-table/bootstrap-table.min.css">
<link rel="stylesheet" href="./js/bootstrap-multiselect/bootstrap-multiselect.css" type="text/css"/>
<link rel="stylesheet" href="./js/bootstrap-3.3.5-dist/css/bootstrap-datetimepicker.css">

<script type="text/javascript" src="./js/jquery-1.11.3.min.js"></script>
<script type="text/javascript" src="./js/bootstrap-3.3.5-dist/js/bootstrap.js"></script>
<script type="text/javascript" src="./js/metisMenu/metisMenu.js"></script>
<script type="text/javascript" src="./js/common.js"></script>
<script src="./js/bootstrap-table/bootstrap-table-all.min.js"></script>
<script src="./js/bootstrap-table/bootstrap-table-zh-CN.min.js"></script>
<script src="./js/bootstrap-multiselect/bootstrap-multiselect.js"></script>
<script src="./js/bootstrap-jquery-plugin/jquery.bootstrap.js"></script>
<script src="./js/bootstrap-3.3.5-dist/js/bootstrap-datetimepicker.js"></script>
<script src="./js/bootstrap-3.3.5-dist/js/bootstrap-datetimepicker.zh-CN.js"></script>

</head>
<body>
	<jsp:include page="../template/head.jsp" />
	<jsp:include page="../template/leftnav.jsp" />
	<div id="page-wrapper">
		<div class="wrapper">
			<h1><a href="./jsp/illness/illness.jsp">药品列表</a></h1><h3> <span> > </span> 药品详情</h3>
		</div>
		<div class="bHead">
			<ul class="list-inline">	
				<li style="width: 60%;">
					<label>药品名称：</label>
					<input class="form-control" style="display:-webkit-inline-box;width: inherit;" id="name";/>
					<span class="btn detail—btn" onclick="editill()" id="editill">修改</span>
					<span class="btn detail—btn" onclick="confirmill()" id="confirmill">确认</span>
					<span class="btn detail—btn" onclick="cancelill()" id="cancelill">取消</span>
				</li>
			</ul>
		</div>		
		<div class="i-detail i-detail-info">
			<h3>基本信息</h3>
			<div class="list-inline" style="margin:5px">
				<label>&nbsp;&nbsp;&nbsp;&nbsp;皮试：</label>
				<input class="form-control" style="width:85% !important; display:-webkit-inline-box;width: inherit;" id="skinTest" placeholder="请输入‘需要’或‘不需要’"/>
			</div>
			<div class="list-inline" style="margin:5px">
				<label>&nbsp;&nbsp;&nbsp;&nbsp;用法：</label>
				<textarea class="form-control" style="width:85% !important; display:-webkit-inline-box;width: inherit;" id="medicineUsage"></textarea>
			</div>
			<div class="list-inline" style="margin:5px">
				<label>&nbsp;&nbsp;&nbsp;&nbsp;概述：</label>
				<textarea class="form-control" style="width:85% !important; display:-webkit-inline-box;width: inherit;" id="details"></textarea>
			</div>				
			<div class="list-inline" style="margin:5px">
				<label>副作用：</label>
				<textarea class="form-control" style="width:85% !important; display:-webkit-inline-box;width: inherit;" id="sideEffect"></textarea>
			</div>
			<div class="list-inline" style="margin:5px">
				<label>禁忌症：</label>
				<textarea class="form-control" style="width:85% !important; display:-webkit-inline-box;width: inherit;" id="taboo"></textarea>
			</div>
		</div>
		
</body>
<script type="text/javascript">
	var id = $.getUrlParam("id");
	
	$(function (){
		$.ajax({
           url: "./medicine/getMedicineInfo",
           data: {
               id: id
           },
           type: "GET",
           dataType: 'json',
           cache: false,
           success: function (ret) {
             	$("#name").val(ret.content.name);
           		$("#details").val(ret.content.details);
           		$("#medicineUsage").val(ret.content.medicineUsage);
           		$("#sideEffect").val(ret.content.sideEffect);
           		$("#skinTest").val(ret.content.skinTest==1?"需要":"不需要");
           		$("#taboo").val(ret.content.taboo);
           		
           		$("#name").attr({readonly:'true'});
           		$("#details").attr({readonly:'true'});
           		$("#medicineUsage").attr({readonly:'true'});
           		$("#sideEffect").attr({readonly:'true'});
           		$("#skinTest").attr({readonly:'true'});
           		$("#taboo").attr({readonly:'true'});
           		
           		$("#editill").show();
		       	$("#confirmill").hide();
		       	$("#cancelill").hide();
           }
       });
	});
	
	function editill(){
      	$("#name").removeAttr("readonly");
      	$("#details").removeAttr("readonly");
      	$("#medicineUsage").removeAttr("readonly");
      	$("#sideEffect").removeAttr("readonly");
      	$("#skinTest").removeAttr("readonly");
     	$("#taboo").removeAttr("readonly");
        $("#editill").hide();
        $("#confirmill").show();
        $("#cancelill").show();
	}
	
	function confirmill(){
		var name = $("#name").val();
		var details = $("#details").val();
		var medicineUsage = $("#medicineUsage").val();
    	var sideEffect = $("#sideEffect").val();
   		var skinTest = $("#skinTest").val();
   		var taboo = $("#taboo").val();
       	var obj = {
       		id:id,
        	name:name,
			usage:medicineUsage,
			sideEffect:sideEffect,
			skinTest:skinTest=="需要"?1:0,
			taboo:taboo,
			details:details
        };
		$.messager.model = { 
			//定义消息提示框
		   	ok:{ text: "确定", classed: 'btn btn-success' },
		    cancel:{text:"取消",classed: 'btn btn-error' }
		};
		$.messager.confirm("温馨提示", "确定更改药品?", function(){
			$.ajax({
				url: "./medicine/updateMedicine",
				data:obj,
				type: "POST",
				dataType: 'json',
				cache: false,
				success: function(ret) {
					if(ret.resultCode==0){
						$.messager.popup("修改成功");
						location.reload();
					}else{
						$.messager.popup("修改失败");
					}
				}
			});
		});
	}
	
	function cancelill(){
   		$("#name").attr({readonly:'true'});
   		$("#details").attr({readonly:'true'});
   		$("#medicineUsage").attr({readonly:'true'});
   		$("#sideEffect").attr({readonly:'true'});
   		$("#skinTest").attr({readonly:'true'});
   		$("#taboo").attr({readonly:'true'});
        $("#editill").show();
        $("#confirmill").hide();
        $("#cancelill").hide();
	}
</script>
</html>
